import scipy.integrate as integrate
from numpy import sqrt
from numpy import arange


def norm1(f):
    ans, abs_err = integrate.quad(lambda x: abs(f(x)), -1, 1)
    return ans / 2, (ans - abs_err) / 2, (ans + abs_err) / 2


def norm2(f):
    ans, abs_err = integrate.quad(lambda x: f(x) ** 2, -1, 1)
    return sqrt(ans / 2), sqrt(ans / 2 - abs_err / 2), sqrt(ans / 2 + abs_err / 2)


def norm_inf(f):
    return max(abs(f(arange(-1, 1, 2 ** (-20)))))
